<form action="" id="home-ad"  method="post">
    <div class="col-xs-12 col-md-12 col-lg-12 padding-none lists _data_ad_image">
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right"></div>
            <div class="col-md-7 filed-from padding-none">
                <img class="thumb _thumb"  data-toggle="tooltip" data-placement="top" title="建议上传100 X 200(px)的.jpg图片" src="<?php echo $data['image_ad']['image'] ? cutUrl($data['image_ad']['image'],100,100) : '/statics/common/images/image.png' ?>" width="100" height="100">
            </div>
        </div>
        <?php

            $selected = [
                    'go_category' => 'go_category',
                    'go_goods' => 'go_goods',
                    'go_special' => 'go_special',
                    'go_activity' => 'go_activity',
                    'go_page' => 'go_page',
                ];

            $$selected[$data['image_ad']['type']] = 'selected';

        ?>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">跳转到 :</div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <select name="" class="form-control radius-none">
                    <option data-name="分类ID" <?php echo $go_category?> value="go_category">跳转到分类</option>
                    <option data-name="商品ID" <?php echo $go_goods?> value="go_goods">跳转到商品</option>
                    <option data-name="专题ID" <?php echo $go_special?> value="go_special">跳转到专题</option>
                    <option data-name="活动ID" <?php echo $go_activity?> value="go_activity">跳转到活动</option>
                    <option data-name="页面连接" <?php echo $go_page?> value="go_page">跳转到页面</option>
                </select>
            </div>
        </div>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right"></div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <div class="input-group">
                    <span class="input-group-addon radius-none">分类ID</span>
                    <input type="text"  class="form-control radius-none" value="<?php echo $data['image_ad']['type_val']?>">
                </div>
            </div>
        </div>
    </div>
    <div class="col-xs-12 col-md-12 col-lg-12 padding-none lists _data">
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right"></div>
            <div class="col-md-7 filed-from padding-none">
                <img class="thumb _thumb"  data-toggle="tooltip" data-placement="top" title="建议上传100 X 100(px)的.jpg图片" src="<?php echo cutUrl($data['ad'][0]['image'],100,100) ? cutUrl($data['ad'][0]['image'],100,100) : '/statics/common/images/image.png' ?>" data-src="<?php echo cutUrl($data['ad'][0]['image'],100,100) ? cutUrl($data['ad'][0]['image'],100,100) : '/statics/common/images/image.png' ?>" width="100" height="100">
            </div>
        </div>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">标题 :</div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <input type="text" name="title" value="<?php echo $data['ad'][0]['title']?>" class="form-control radius-none">
            </div>
        </div>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">描述 :</div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <textarea name="description" class="form-control radius-none"><?php echo $data['ad'][0]['description']?></textarea>
            </div>
        </div>
        <?php

        $selected = [
                    'go_category' => 'go_category',
                    'go_goods' => 'go_goods',
                    'go_special' => 'go_special',
                    'go_activity' => 'go_activity',
                    'go_page' => 'go_page',
                ];

        foreach($selected as $v){

            $$v = '';

        }

        $$selected[$data['ad'][0]['type']] = 'selected';

        ?>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">跳转到 :</div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <select name="type" class="form-control radius-none">
                    <option data-name="分类ID" <?php echo $go_category?> value="go_category">跳转到分类</option>
                    <option data-name="商品ID" <?php echo $go_goods?> value="go_goods">跳转到商品</option>
                    <option data-name="专题ID" <?php echo $go_special?> value="go_special">跳转到专题</option>
                    <option data-name="活动ID" <?php echo $go_activity?> value="go_activity">跳转到活动</option>
                    <option data-name="页面连接" <?php echo $go_page?> value="go_page">跳转到页面</option>
                </select>
            </div>
        </div>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right"></div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <div class="input-group">
                    <span class="input-group-addon radius-none">分类ID</span>
                    <input name="type_val" type="text"  class="form-control radius-none" value="<?php echo $data['ad'][0]['type_val']?>">
                </div>
            </div>
        </div>
    </div>
    <div class="col-xs-12 col-md-12 col-lg-12 padding-none lists _data">
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right"></div>
            <div class="col-md-7 filed-from padding-none">
                <img class="thumb _thumb"  data-toggle="tooltip" data-placement="top" title="建议上传100 X 100(px)的.jpg图片" src="<?php echo cutUrl($data['ad'][1]['image'],100,100) ? cutUrl($data['ad'][1]['image'],100,100) : '/statics/common/images/image.png' ?>" data-src="<?php echo cutUrl($data['ad'][1]['image'],100,100) ? cutUrl($data['ad'][1]['image'],100,100) : '/statics/common/images/image.png' ?>" width="100" height="100">
            </div>
        </div>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">标题 :</div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <input type="text" name="title" value="<?php echo $data['ad'][1]['title']?>" class="form-control radius-none">
            </div>
        </div>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">描述 :</div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <textarea name="description" class="form-control radius-none"><?php echo $data['ad'][1]['description']?></textarea>
            </div>
        </div>
        <?php

            $selected = [
                'go_category' => 'go_category',
                'go_goods' => 'go_goods',
                'go_special' => 'go_special',
                'go_activity' => 'go_activity',
                'go_page' => 'go_page',
            ];

            foreach($selected as $v){

                $$v = '';

            }

            $$selected[$data['ad'][1]['type']] = 'selected';

        ?>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">跳转到 :</div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <select name="type" class="form-control radius-none">
                    <option data-name="分类ID" <?php echo $go_category?> value="go_category">跳转到分类</option>
                    <option data-name="商品ID" <?php echo $go_goods?> value="go_goods">跳转到商品</option>
                    <option data-name="专题ID" <?php echo $go_special?> value="go_special">跳转到专题</option>
                    <option data-name="活动ID" <?php echo $go_activity?> value="go_activity">跳转到活动</option>
                    <option data-name="页面连接" <?php echo $go_page?> value="go_page">跳转到页面</option>
                </select>
            </div>
        </div>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right"></div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <div class="input-group">
                    <span class="input-group-addon radius-none">分类ID</span>
                    <input name="type_val" type="text"  class="form-control radius-none" value="<?php echo $data['ad'][1]['type_val']?>">
                </div>
            </div>
        </div>
    </div>
    <div class="col-xs-12 col-md-12 col-lg-12 padding-none lists _data">
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right"></div>
            <div class="col-md-7 filed-from padding-none">
                <img class="thumb _thumb"  data-toggle="tooltip" data-placement="top" title="建议上传100 X 100(px)的.jpg图片" src="<?php echo cutUrl($data['ad'][2]['image'],100,100) ? cutUrl($data['ad'][2]['image'],100,100) : '/statics/common/images/image.png' ?>" data-src="<?php echo cutUrl($data['ad'][2]['image'],100,100) ? cutUrl($data['ad'][2]['image'],100,100) : '/statics/common/images/image.png' ?>" width="100" height="100">
            </div>
        </div>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">标题 :</div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <input type="text" name="title" value="<?php echo $data['ad'][2]['title']?>" class="form-control radius-none">
            </div>
        </div>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">描述 :</div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <textarea name="description" class="form-control radius-none"><?php echo $data['ad'][2]['description']?></textarea>
            </div>
        </div>
        <?php

            $selected = [
                'go_category' => 'go_category',
                'go_goods' => 'go_goods',
                'go_special' => 'go_special',
                'go_activity' => 'go_activity',
                'go_page' => 'go_page',
                ];

        foreach($selected as $v){

            $$v = '';

        }

        $$selected[$data['ad'][1]['type']] = 'selected';

        ?>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">跳转到 :</div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <select name="type" class="form-control radius-none">
                    <option data-name="分类ID" <?php echo $go_category?> value="go_category">跳转到分类</option>
                    <option data-name="商品ID" <?php echo $go_goods?> value="go_goods">跳转到商品</option>
                    <option data-name="专题ID" <?php echo $go_special?> value="go_special">跳转到专题</option>
                    <option data-name="活动ID" <?php echo $go_activity?> value="go_activity">跳转到活动</option>
                    <option data-name="页面连接" <?php echo $go_page?> value="go_page">跳转到页面</option>
                </select>
            </div>
        </div>
        <div class="col-xs-12 col-md-12 col-lg-12 padding-none" style="margin-top: 10px;">
            <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right"></div>
            <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
                <div class="input-group">
                    <span class="input-group-addon radius-none">分类ID</span>
                    <input name="type_val" type="text"  class="form-control radius-none" value="<?php echo $data['ad'][2]['type_val']?>">
                </div>
            </div>
        </div>
    </div>
    <div class="col-xs-12 col-md-12 col-lg-12 lists text-right">
        <input type="submit" name="dosubmit" value="保存" class="btn btn-success radius-none">
        <input type="reset"  value="重置" class="btn btn-info radius-none">
    </div>
</form>
<script>
    //储存节点对象
    var $setting = {}

    $(function(){

        Admin.upload('._thumb',false,function(objects){

            $setting.images = objects;

        });
        $('[data-toggle="tooltip"]').tooltip();

        $('#home-ad').undelegate('select','change');
        $('#home-ad').delegate('select','change',function(){

            var _this = $(this);

            var name = $('option:selected',_this).data('name');

            _this
                    .parent()
                    .parent()
                    .next()
                    .children()
                    .children()
                    .children('span')
                    .text(name)


        });

        //提交数据
        $('form#home-ad').submit(function(){

            var data = {};
            data.image_ad = {}
            data.ad = []

            data.image_ad.image = $('img','._data_ad_image').data('src');
            data.image_ad.type = $('select option:selected','._data_ad_image').val();
            data.image_ad.type_val = $('input','._data_ad_image').val();

            $('._data',$(this)).each(function(){

                var ad_info = {}
                ad_info.image = $('img',$(this)).data('src');
                ad_info.title = $('[name="title"]',$(this)).val();
                ad_info.description = $('[name="description"]',$(this)).val();
                ad_info.type = $('[name="type"]',$(this)).val();
                ad_info.type_val = $('[name="type_val"]',$(this)).val();

                data.ad.push(ad_info);

            });


            $.post("<?php echo U('Admin/Setting/Index/setAd')?>",{'data':data},function(result){

                showMessage(result.msg,result.code,'','',2000);

            });
            return false;



        });
    });
    //图片上传回调
    function getImageSrc(_this){

        $setting.images.attr('src',cutUrl(_this[0],200,100));
        $setting.images.data('src',_this[0]);

    }
</script>